import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'

/**
 * 发起坞修
 */

const useDockRepair = defineStore(
  'dockRepair',
  () => {
    const { t, locale } = useI18n()

    // 当前步骤 0为第一步
    const activeStep = ref(0)
    const setActiveStep = (val) => {
      activeStep.value = val
    }

    // 下一步
    const next = () => {
      activeStep.value++
    }

    // 上一步
    const back = () => {
      activeStep.value--
    }

    // 步骤名
    const steplist = ref([
      'step1',
      'step2',
      'step3'
      // , 'step4'
    ])

    // 步骤描述
    const stepDesc = computed(() => {
      return t(`dockRepair.${steplist.value[activeStep.value]}Desc`)
    })

    // 船舶信息
    const ship = ref({})
    const setShip = (val) => {
      ship.value = val
    }

    // 坞修单 id、编号orderNo、名称dockOrderName、维修次数count、维修性质nature
    const orderInfo = ref({})
    const setOrderInfo = (val) => {
      orderInfo.value = val
    }
    const setOrderInfoKey = (key, val) => {
      orderInfo.value[key] = val
    }

    // 询价参数
    const inquiryParams = ref({})
    const setInquiryParams = (val) => {
      inquiryParams.value = val
    }

    // 重置
    const reset = () => {
      activeStep.value = 0
      ship.value = {}
      orderInfo.value = {}
      inquiryParams.value = {}
    }

    return {
      activeStep,
      setActiveStep,
      next,
      back,
      steplist,
      stepDesc,
      ship,
      setShip,
      orderInfo,
      setOrderInfo,
      setOrderInfoKey,
      inquiryParams,
      setInquiryParams,
      reset
    }
  },
  {
    persist: {
      enabled: false,
      strategies: [
        {
          storage: localStorage
        }
      ]
    }
  }
)

export default useDockRepair
